package List;

import java.util.*;


/**
 * List排序的编码实现
 * 输出结果
 * 排序前输出结果：
 * [Worker{name='sjx', age=27, salary=1300.0}, Worker{name='cbc', age=22, salary=3100.0},
 * Worker{name='xpf', age=26, salary=4300.0}, Worker{name='zz', age=29, salary=2300.0}]
 * 排序后输出结果：
 * [Worker{name='xpf', age=26, salary=4300.0}, Worker{name='cbc', age=22, salary=3100.0},
 * Worker{name='zz', age=29, salary=2300.0}, Worker{name='sjx', age=27, salary=1300.0}]
 */
public class ListSort {

    public static void main(String[] args) {
        List<Worker> list = new ArrayList<>();
        list.add(new Worker("sjx", 27, 1300F));
        list.add(new Worker("cbc", 22, 3100F));
        list.add(new Worker("xpf", 26, 4300F));
        list.add(new Worker("zz", 29, 2300F));
        System.out.println(list);
        Collections.sort(list, new Comparator<Worker>() {
            @Override
            public int compare(Worker o1, Worker o2) {
                return (int) (o2.getSalary() - o1.getSalary());
            }
        });
        System.out.println(list);
    }

}
